package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.commons.ServerResponse;
import com.chixing.pojo.EducationalExperience;
import com.chixing.pojo.ExperienceProject;
import com.chixing.mapper.ExperienceProjectMapper;
import com.chixing.service.IExperienceProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 项目经历 服务实现类
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@Service
public class ExperienceProjectServiceImpl  implements IExperienceProjectService {
    @Autowired(required = false)
    private ExperienceProjectMapper projectMapper;
    @Override
    public ExperienceProject getProjectById(Integer myresumeId) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("myresume_id",myresumeId);
//        根据myresumeId查得结果
        List<ExperienceProject> projectList = projectMapper.selectList(wrapper);
        System.out.println("myserviceImpl-personAll>>>>>"+ projectList.get(0));//获取list第一条信息
        ExperienceProject experienceProject = projectList.get(0);
        return experienceProject;
    }

    @Override
    public ServerResponse updateProjectById(ExperienceProject experienceProject,Integer myresumeId) {
        QueryWrapper<ExperienceProject> wrapper = new QueryWrapper<>();
        wrapper.eq("myresume_id",myresumeId);
        ExperienceProject projectSql = projectMapper.selectOne(wrapper);

        projectSql.setProjectName(experienceProject.getProjectName());
        projectSql.setProjectOperation(experienceProject.getProjectOperation());
        projectSql.setProjectUrl(experienceProject.getProjectUrl());
        projectSql.setProjectCreateTime(experienceProject.getProjectEndTime());
        projectSql.setProjectEndTime(experienceProject.getProjectEndTime());
        projectSql.setProjectPerformance(experienceProject.getProjectPerformance());
        projectSql.setProjectDescription(experienceProject.getProjectDescription());

        int  projectUpdate= projectMapper.updateById(projectSql);
        if (projectUpdate>0){
            return ServerResponse.success("ExperienceProject表修改成功",null);
        }
        return ServerResponse.fail("ExperienceProject表修改失败",null);
    }
}
